import ij.ImagePlus;
import ij.plugin.filter.PlugInFilter;
import ij.process.ColorProcessor;
import ij.process.ImageProcessor;
import color.RgbHsv;

/* This plugin rotates the color hue by 120 degrees */

public class Color_Hsv_Test implements PlugInFilter {

	public int setup(String arg, ImagePlus imp) {
		return DOES_RGB;
	}

	public void run(ImageProcessor ip) {
		ColorProcessor cp = (ColorProcessor) ip;
		int[] RGB = new int[3];
		float[] HSV = new float[3];
		
		for (int v = 0; v < cp.getHeight(); v++) {
			for (int u = 0; u < cp.getWidth(); u++) {
				cp.getPixel(u, v, RGB);

				RgbHsv.RGBtoHSV (RGB, HSV); // all HSV components are in [0,1]
				HSV[0] = (HSV[0] + 1.0f/3) % 1.0f;	// = 120 degrees
				RgbHsv.HSVtoRGB(HSV, RGB);

				cp.putPixel(u, v, RGB);
			}
		}
	}
}